package com.wendu.oa.dao.info;

import com.wendu.oa.dto.EmployeeDto;
import com.wendu.oa.model.Employee;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

@Mapper
public interface EmpDao {
    List<Employee> findEmpList(EmployeeDto employeeDto);

    @Insert("insert into t_emp(e_id,e_name,e_sex,e_birth,d_id) values (#{e_id},#{e_name},#{e_sex},#{e_birth},#{d_id})")
    void insertEmp(EmployeeDto employeeDto);

    @Insert("update  t_emp set e_name = #{e_name},e_sex = #{e_sex} ,e_birth = #{e_birth} ,d_id = #{d_id} where e_id = #{e_id}")
    void updateEmp(EmployeeDto employeeDto);

    @Delete("delete from t_emp where e_id= #{eid}")
    void deleteEmp(String eid);

    @Select("select d_id from t_emp where e_id = #{eid}")
    Integer findDepIdByEmpId(String eid);

    @Select("select ifnull(max(mgr_id),0) from t_mgr")
    int findMgrMaxId();

    @Insert("insert into t_mgr(mgr_id,e_id,d_id) values(#{mgr_id},#{e_id},#{d_id})")
    void insertMgr(@Param("mgr_id") int newMgrId, @Param("e_id")String eid, @Param("d_id")Integer depId);

    @Insert("insert into t_user(u_id,u_name,u_pwd) select e_id,e_name,123456 from t_emp where e_id = #{eid}")
    void insertNewUser(String eid);

    @Delete("delete from t_mgr where d_id = #{depId}")
    void deleteOtherLeaders(Integer depId);
}
